package com.zlh.service.impl;


import com.github.pagehelper.PageHelper;
import com.zlh.mapper.EbOrderDetailMapper;
import com.zlh.mapper.EbOrderMapper;
import com.zlh.model.EbOrder;
import com.zlh.model.EbOrderExample;
import com.zlh.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
@Autowired
    private EbOrderMapper ebOrderMapper;
@Autowired
    private EbOrderDetailMapper ebOrderDetailMapper;
@Override
public List<EbOrder> list(Integer page, int pageSize) {
    //web--service-dao/mapper
    PageHelper.startPage(page,pageSize);
    List<EbOrder> ebOrders = ebOrderMapper.selectByExample(null);
    return ebOrders;
}

    @Override
    public int save(EbOrder ebOrder) {
            return 5;

    }

    public int update(EbOrder ebOrder){
        return ebOrderMapper.updateByPrimaryKeySelective(ebOrder);
    }
    @Override

    public EbOrder selectOne(Integer eoId) {
        return ebOrderMapper.selectOne(eoId);
    }
    /**
     * 删除
     */
    public int delete(int eoId){
        return ebOrderMapper.deleteByPrimaryKey(eoId);
    }

    /**
     * 查询
     */
    public List<EbOrder> selectSuccess(int eoId,String eoUserName,int page,int pageSize){
        PageHelper.startPage(page,pageSize);
        EbOrderExample ebOrderExample = new EbOrderExample();
        EbOrderExample.Criteria criteria = ebOrderExample.createCriteria();
        if(eoId ==0 && eoUserName != null){
            criteria.andEoUserNameEqualTo(eoUserName);
        }else if(eoId !=0 || eoUserName==null){
            criteria.andEoIdEqualTo(eoId);
        }else{
            criteria.andEoIdLessThanOrEqualTo(eoId).andEoUserNameLessThanOrEqualTo(eoUserName);
        }
        return ebOrderMapper.selectByExample(ebOrderExample);
    }


}
